import { AddUserType, UpdateUserTpye, User, UserQuery } from './../types/user'
import request from '../utils/request'
import { ApiRes } from '@/types/data'

export const login = (data: { adminname: string; password: string }) => {
  return request<ApiRes<User>>({
    url: 'admin/login',
    method: 'POST',
    data
  })
}
//获取用户信息
export const getUserInfo = () => {
  return request<ApiRes<User>>({
    url: 'admin/detail'
  })
}
//分页获取用户列表
export const getUserList = (params: UserQuery) => {
  return request<ApiRes<{ total: number; items: User[] }>>({
    url: 'admin/list',
    params
  })
}
//增加用户
export const addUser = (data: AddUserType) => {
  return request({
    url: 'admin/add',
    method: 'POST',
    data
  })
}
//修改用户
export const updateUser = (data: UpdateUserTpye) => {
  return request({
    url: 'admin/update',
    method: 'POST',
    data
  })
}
//删除用户
export const deleteUser = (adminid: string) => {
  return request({
    url: 'admin/delete',
    method: 'POST',
    data: {
      adminid
    }
  })
}
